<template>
  <ContentWrap title="主数据">
    <el-form
      :rules="rules"
      label-position="top"
      :inline="false"
      class="demo-form-inline"
      :model="ff"
    >
      <el-form-item
        :label="data.label"
        v-for="data in props.detailSchema"
        :key="data.field"
        :prop="data.field"
      >
        <el-input
          v-model="ff.code"
          v-if="data.field == 'code'"
          :placeholder="`请输入相应的${data.label}`"
          :clearable="true"
          style="width: 200px"
        />

        <ElInput
          v-if="data.field == 'name'"
          @click="aax"
          v-model="ff.name"
          placeholder="点击选择"
          v-bind="$attrs"
          style="width: 200px"
        />

        <el-date-picker
          v-if="data.field == 'creation_time'"
          v-model="ff.creation_time"
          type="date"
          placeholder="请输入相应的创建时间"
          :clearable="true"
        />
        <el-select
          v-if="data.field == 'creation_user_name'"
          v-model="ff.creation_user_name"
          class="m-2"
          placeholder="请输入"
        >
          <el-option
            v-for="item in options[0]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-select
          v-if="data.field == 'address'"
          v-model="ff[data.field]"
          class="m-2"
          placeholder="请输入"
          :disabled="ff.creation_user_name == '入库' || ff.creation_user_name == ''"
        >
          <el-option
            v-for="item in options[1]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-select
          v-if="data.field == 'legal_name'"
          v-model="ff[data.field]"
          class="m-2"
          placeholder="请输入"
          :disabled="ff.creation_user_name == '出库' || ff.creation_user_name == ''"
        >
          <el-option
            v-for="item in options[2]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>

        <el-input
          v-model="ff.operator_name"
          v-if="data.field == 'operator_name'"
          :placeholder="`请输入相应的${data.label}`"
          :clearable="true"
          style="width: 200px"
        />
      </el-form-item>
    </el-form>
    <Dialog v-model="dialogVisible" title="选">
      <Mu @shi="fff" />
    </Dialog>
  </ContentWrap>
</template>
<!-- || data.field == 'address' || data.field == 'legal_name' -->
<script setup lang="ts">
import { PropType, reactive, ref } from 'vue'
import { required } from '@/utils/formRules'
import type { FormRules } from 'element-plus'

import Mu from '@/views/AAA/Mu.vue'
// prop值
const props = defineProps({
  currentRow: {
    type: Object as PropType<Nullable<any>>,
    default: () => null
  },
  detailSchema: {
    type: Array as PropType<DescriptionsSchema[]>,
    default: () => []
  },
  id: {
    type: String,
    default: null
  }
})
console.log(props.detailSchema)

const rules = reactive<FormRules>({
  code: [required],
  name: [required],
  address: [required],
  legal_name: [required],
  creation_time: [required]
  // operator_name: [required]
})
// 结束后填写的信息
const ff = ref({
  code: '',
  name: '',
  address: '',
  legal_name: '',
  creation_time: '',
  operator_name: '',
  creation_user_name: ''
})
defineExpose([ff])
const options = [
  [
    {
      value: '出库',
      label: '出库'
    },
    {
      value: '入库',
      label: '入库'
    }
  ],
  [
    {
      value: '领用',
      label: '领用'
    },
    {
      value: '调拨中',
      label: '调拨中'
    },
    {
      value: '红冲',
      label: '红冲'
    },
    {
      value: '盘亏',
      label: '盘亏'
    }
  ],
  [
    {
      value: '采购入库',
      label: '采购入库'
    },
    {
      value: '调拨中',
      label: '调拨中'
    },
    {
      value: '红冲',
      label: '红冲'
    },
    {
      value: '盘赢',
      label: '盘赢'
    }
  ]
]

// 点击弹出人员
const aax = () => {
  dialogVisible.value = true
}
const dialogVisible = ref(false)
// 自定义按钮
const fff = (row) => {
  // console.log(row, '1234')
  dialogVisible.value = false
  ff.value.name = row.name
}

// (修改) 调用查看接口获取信息
const getMedicalOrderSee = async () => {
  console.log(props.id)
  if (props.id) {
    // const res = await adminFaMedicalOrderSeeApi({ id: props.id })
    //   .catch(() => {})
    //   .finally(() => {})
    // if (res) {
    //   data.value = await changeDId(res.data)
    //   console.log(props.id, res)
    //   // 明细信息处理一下，加上d_id
    //   await methods.setValues(data.value)
    // }
    ff.value = {
      code: 'giao',
      name: 'jj牧场',
      legal_name: '部分盘点',
      operator_name: '223333',
      address: '',
      creation_time: '',
      creation_user_name: ''
    }
    // await methods.setValues(ff.value)
  } else {
    ff.value.address = ''
    ff.value.operator_name = ''
    // ff.value.fileData = []
  }
}
const init = async () => {
  // 调用查看接口查询数据
  await getMedicalOrderSee()
}
init()
</script>

<style lang="scss" scoped>
.el-form {
  display: flex;
  flex-wrap: wrap;
}
.el-form > div {
  width: 50%;
}
.m-2 {
  margin: 0;
}
</style>
